package show.me.the.money.keyserver;

import java.net.*;
import java.util.ArrayList;
import java.util.List;
import java.io.*;

import show.me.the.money.util.keyManager.KeyManager;


public class MyServer extends Thread{
	
	private Socket s = null;
	private ServerSocket ss = null;
	
	public MyServer(Socket s,ServerSocket ss){
		this.s = s;
		this.ss = ss;
	}
	
	public void run() {
	/*	
		try {
			DataInputStream din = new DataInputStream(s.getInputStream());
			ObjectOutputStream dout = new ObjectOutputStream(s.getOutputStream());
			int n = din.readInt();
			if(ss.getSoTimeout()==0){
				ss.setSoTimeout(3000);
			}
			dout.writeObject(new User("hello",23));
			//dout.writeObject(false);
			din.close();
			dout.close();
		} catch (IOException e) {
			System.out.println(e.getMessage());
		}
		*/
		
		try {
			Thread.sleep(5000);
			System.out.println("set...");
			//ss.setSoTimeout(3000);		
			ss.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

	public static void main(String[] args) throws Exception{
	
		//KeyManager.init("localhost",9001);
		
	    ServerSocket ss = new ServerSocket(8899,10,InetAddress.getByName("172.16.170.44"));
	    Socket s = null;
	    String id = "";
		while(true){
			s = ss.accept();
			
			ObjectInputStream din = new ObjectInputStream(s.getInputStream());
			Object obj = din.readObject();
			if(obj instanceof ArrayList){
				List l = (ArrayList)obj;
				id = KeyManager.getKeyByName("daytest2",l);
				System.out.println(id);
			}
			ObjectOutputStream dout = new ObjectOutputStream(s.getOutputStream());
			//dout.writeUTF("server="+n+"---"+din.readUTF());
			dout.writeObject(id);
			din.close();
			dout.close();
		}

	}

}
